const mongoose = require('mongoose');
const chalk = require('chalk');
const detailData = require('@root/initDatas/detail.json')

let initData = {}
Object.keys(detailData).forEach(key => {
  initData[key] = {}
  Object.keys(detailData[key]).forEach(key2 => {
    initData[key][key2] = JSON.parse(detailData[key][key2].body)
  })
})

// console.log(initData['162958680'].rst)

const detailSchema = mongoose.Schema({
    bought_list: {
      food_ids: [Number],
      grey_icon_url: String,
      icon_url: String,
      text: String
    },
    menu: [{
      id: Number,
      name: String,
      description: String,
      foods: [Object],
      _type: Number,
      is_activity: Number,
      activity: Object,
      icon_url: String,
      is_selected: Boolean,
      grey_icon_url: String,
      global_id: String,
    }],
    recommend: [{
        items: [Object],
        name: String,
        window_type: Number
    }],
    rst: {
      activities: [
        {
          attribute: String,
          description: String,
          icon_color: String,
          icon_name: String,
          id: Number,
          is_exclusive_with_food_activity: Boolean,
          name: String,
          tips: String,
          _type: Number
        }
      ],
      address: String,
      albums: [
        {
          count: Number,
          cover_image_hash: String,
          name: String,
          photos: [Array]
        }
      ],
      authentic_id: Number,
      business_info: String,
      delivery_mode: {
        border: String,
        color: String,
        icon_hash: String,
        id: Number,
        is_solid: Boolean,
        text: String,
        text_color: String
      },
      description: String,
      distance: Number,
      favored: Boolean,
      flavors: [ { id: Number, name: String }, { id: Number, name: String } ],
      float_delivery_fee: Number,
      float_minimum_order_amount: Number,
      has_story: Boolean,
      id: Number,
      image_path: String,
      is_new: Boolean,
      is_premium: Boolean,
      is_stock_empty: Number,
      is_valid: Number,
      latitude: Number,
      longitude: Number,
      max_applied_quantity_per_order: Number,
      name: String,
      next_business_time: String,
      only_use_poi: Boolean,
      opening_hours: [ String ],
      order_lead_time: Number,
      phone: String,
      piecewise_agent_fee: {
        description: String,
        extra_fee: Number,
        is_extra: Boolean,
        no_subsidy_fee: String,
        rules: [ [Object] ],
        tips: String
      },
      platform: Number,
      posters: [
        {
          id: Number,
          image_hash: String,
          name: String,
          url: String
        }
      ],
      promotion_info: String,
      qualification: {
        link: String
      },
      rating: Number,
      rating_count: Number,
      recent_order_num: Number,
      recommend: { is_ad: Boolean, reason: String },
      recommend_reasons: [ { name: String } ],
      regular_customer_count: Number,
      scheme: String,
      shop_sign: {
        brand_story: String,
        image_hash: String
      },
      status: Number,
      support_tags: [
        {
          border: String,
          color: String,
          icon: String,
          text: String,
          _type: Number
        }
      ],
      supports: [],
      theme: {
        default_color: String,
        header_style: Number,
        hongbao_style: Number,
        price_color: String,
        third_tab_name: String,
        vanish_fields: []
      },
      _type: Number,
      weight: { basic: Number, maximum: Number, unit: Number, unit_fee: Number }
    },
    user: {
      avatar: String,
      balance: Number,
      brand_member_new: Number,
      column_desc: {
        game_desc: String,
        game_image_hash: String,
        game_is_show: Number,
        game_link: String,
        gift_mall_desc: String
      },
      current_address_id: Number,
      current_invoice_id: Number,
      delivery_card_expire_days: Number,
      email: String,
      gift_amount: Number,
      id: Number,
      is_active: Number,
      is_email_valid: Boolean,
      is_mobile_valid: Boolean,
      mobile: String,
      point: Number,
      real_point: Number,
      supervip_status: Number,
      user_id: Number,
      username: String
    }
})


const detailModel = mongoose.model('detail', detailSchema)

// 初始化数据
// Object.keys(initData).forEach(key => {
//   let data = new detailModel(initData[key])
//   data.save((err, data) => {
//     if(err) return console.log(err)
//   })
// })

module.exports = detailModel